<?php

namespace app\common\model\tyyh;

class User extends CUBase {
	protected $append = ['identity'];
	protected $hidden = ['password', 'salt'];
	protected $privacyFields = ['spreadid'];

	private $createData = [
		'photo'     => '/uploads/20250409/a22cd7578b265d8aad9fb066c3b251ac.png',
		'nickname'  => '新用户',
		'username'  => '',
		'phone'     => '',
		'order_num' => 0
	];

	public function create4phone($phone) {
		$data = array_merge([], $this->createData);
		$data['phone'] = $phone;
		$this->save($data);
		return $this->id;
	}

	public function getIdentityAttr($value, $data) {
		if(empty($data) || !isset($data['id'])) {
			return null;
		}
		$model = loadModel('tyyh\\GroupBuying');
		$row = $model->where(['uid' => $data['id']])->find();
		if(empty($row)) {
			return null;
		} else {
			return ['lv' => $row['lv'], 'text' => loadEnum('GroupBuyingLv')->get_options()[$row['lv']]];
		}
	}
}